﻿import flash.external.*


// 预先生成按钮控件
var cmp_list:Array = new Array();	// 元件列表
var init_pos:Array = new Array(); // 初始化位置列表
function init_cmp()
{
	//ExternalInterface.call("t_tools_plane.creates","开始",init_pos.length,0);
	cmp_list.splice(0,cmp_list.length); //清空
	for(i = 0; i < init_pos.length; i+=2)
	{
		posx = init_pos[i];
		posy = init_pos[i+1];
		cname = "bt_ck"+i
		cardc = plane_tools.attachMovie("bt_ck", cname, i);  //由库中的元件创建
		cardc._x = posx;             //x坐标
		cardc._y = posy; 
		cardc._visible = true
		cmp_list.push(cardc);
		//ExternalInterface.call("t_tools_plane.creates",i,posx,posy);
	}
}
// 设置控件属性  //索引，名称，图片地址，类型背景图片
function set_grid( _i:Number, _nam:String, _img:String, _img_type:String, type:String)
{
    cardc = cmp_list[_i];
	cardc.txt_name.text = _nam;
	cardc.bg.source = _img_type;
	cardc.img.source = _img;
	//ExternalInterface.call("t_tools_plane.creates",_i,cardc._x,cardc._y);
	cardc.btn.addEventListener("click", 
		function ()
		{
			//ExternalInterface.call("t_tools_plane.creates",type,_nam,3);
			ExternalInterface.call("t_tools_plane.btnclick",type , _nam);
		});
	//cardc.img_card.onPress = function()
	//{
		//.call("tools_plane.show_card_info",_nam);
	//}
	cardc.btn.addEventListener("rollOut", 
		function()
		{
			ExternalInterface.call("t_tools_plane.hide_info",type , _nam);
		});
	cardc.btn.addEventListener("rollOver", 
		function(e:Object)
		{
			ExternalInterface.call("t_tools_plane.show_info",type , _nam,e._x,e._y);
		});
}

function btn_change_num(_i:Number, _num:Number)
{
	cardc = cmp_list[_i];
	cardc.txt_num.text = _num
}
function btn_change_isevent(_i:Number, _is:Boolean)
{
	cardc = cmp_list[_i];
	cardc.btn.disabled = _is
}


/////下拉相关///////
pane_bar.setScrollProperties(35,0,160,0);
pane_bar.position = 0;
pane_bar.addEventListener("scroll", this, "on_scroll");
//pane_bar.upArrow.visible = false
//pane_bar.downArrow.visible = false
pane_moveSp = 0;
//控件y坐标
var pane_y:Number = plane_tools._y;

function init_scroll_s(fmove:Number)
{
	pane_bar.position = 0;
}

function on_scroll(e:Object)
{
	plane_tools._y = pane_y - e.position * pane_moveSp;
	ExternalInterface.call("t_tools_plane.tetete",plane_tools._y,pane_moveSp);
}


//鼠标滚轮事件
myListener = new Object();
myListener.onMouseWheel = function(delta)
{
	pane_bar.position -= delta * 6;
	on_scroll(pane_bar);
}
Mouse.addListener(myListener);

//////拖动
// 开始拖动位置
beg_py = 0;
flag = 0;
b = 0;//是否移动
c = 0;//记录鼠标位置
//开始
//plane_tools.onPress = plane_onPress
onMouseDown = plane_onPress
onMouseUp = plane_stopMove
onMouseMove = fMouseMove
//plane_tools.onRollOut = plane_stopMove
function plane_onPress()
{
	flag = 1;
	beg_py = _ymouse;
}
function plane_stopMove()
{
	flag = 0;
}
function fMouseMove()
{
	if (flag == 0)
	{
		return;
	}
	sp = _ymouse - beg_py;
	pane_bar.position -= sp
	on_scroll(pane_bar)
	//if (_ymouse > beg_py)
	//{
		//pane_bar.position -= sp
		//on_scroll(pane_bar)
	//}
	//else
	//{
		//pane_bar.position += sp
		//on_scroll(pane_bar)
	//}
	beg_py = _ymouse;
}



